<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>表模型库编辑首页</title>
<link href="../../static/css/normalize.css?twitterbutton" rel="stylesheet" type="text/css"/>
<link href="../../static/css/tricks.css?twitterbutton" rel="stylesheet" type="text/css"/>
<link href="../../static/css/elusive-webfont.css?twitterbutton" rel="stylesheet" type="text/css"/>
<link href="../../static/css/codemirror.css?twitterbutton" rel="stylesheet" type="text/css"/>
<link href="../../static/css/screen.css?twitterbutton" rel="stylesheet" type="text/css"/>
<link href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
<link href="../../static/plugi/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/easyui/jquery.easyui.ext.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.menu.js" type="text/javascript"></script>
<script src="../../static/js/libs/jquery.cookie.min.js" type="text/javascript"></script>
<a href="" target="_blank" id="commonLink" name="commonLink"></a>
<script languange="javascript">
	var topWin = window;
	function addTab(title, url){
	    if ($('#tt').tabs('exists', title)){
	        $('#tt').tabs('select', title);
	    } else {
	        var content = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
	        $('#tt').tabs('add',{
	            title:title,
	            content:content,
	            closable:true
	        });
	    }
	}
	var projectId = $.getUrlParam('projectId');
	$(function() {
		//使用javascript初始化
		//$('#menu_app1').hide();
		//showTreeMenuBar("menu_app1");
		$(document).attr("title",$.getUrlParam('projectName'));
		$('#centerFrame').attr('src','TableProjectOverview.html?projectId=' + $.getUrlParam('projectId'));
	});
	
	// 刷新导航栏目录结构
	function reloadNavTree(){
		$('#nav').tree('reload');
	}
	
	function listBySubject(){
		/*$.post('projectTreeJson.do',{'project_id':'20151105190313802'},function(data){
			$('#nav').treegrid('loadData',data);
		},'json');
		*/
		$('#nav').tree('options').url = 'esaas.dmcenter.tm.project.tree.bysubject.do?project_id=P20131008093305481121299';
		$('#nav').tree('reload');
	}
	
	function listByPackage(){
		$('#nav').tree('options').url = 'esaas.dmcenter.tm.package.tree.bystd.do?project_id=P20131008093305481121299';
		$('#nav').tree('reload');
	}


	function onContextMenu(e, node) {
		e.preventDefault();
		$(this).tree('select',node.target);
		if (node.attributes.package_type == '2') {
			$('#mm').menu('show',{
				left: e.pageX,
				top: e.pageY
			});
		}
	}

	function reloadPackageTree() {
		reloadNavTree();
		JLEUtil.closewin();
	}

	function doPackageAdd(){
		var node = $('#nav').tree('getSelected');
		JLEUtil.createModalWin('创建下级目录', 'ProjectTmPackageAdd.html?projectId=' + projectId + "&packageAbvId=" + node.id);
	}
	
	function doPackageUpdate(){		
		var node = $('#nav').tree('getSelected');
		JLEUtil.createModalWin('修改当前目录', 'ProjectTmPackageUpdate.html?packageId=' + node.id);
	}
	
	function doPackageView(){
		var node = $('#nav').tree('getSelected');
		JLEUtil.createModalWin('查看当前目录', 'ProjectTmPackageView.html?packageId=' + node.id);
	}
	
	function doPackageDelete(){
		var node = $('#nav').tree('getSelected');
		var packageId = node.id;
		$.restfulGet('../../api/project/tm/package/check/'
				+ packageId, null, function(data) {
			if (data.code == '0') {
				$.messager.confirm('删除提示', '你确定要删除当前目录吗?',
						function(r) {
							if (r) {
								var jsonData = JSON.parse('{' + '"packageId":"'
										+ packageId + '"' + '}');
								$.restfulDelete('../../api/project/tm/package',
										jsonData, function(data) {
											reloadNavTree();
										});
							}
						});				
			} else {
				$.messager.alert('提示', data.message, 'info');
			}
		});
	}

	function doPackageMove() {
		var node = $('#nav').tree('getSelected');
		var packageId = node.id;
		JLEUtil.createModalWin('选择当前目录移动到的目录', `popProjectPackage.html?projectId=${projectId}&callback=updateProjectPackage`);
	}

	function updateProjectPackage(selection) {
		var node = $('#nav').tree('getSelected');
		var jsonData = {
			"packageId" : node.id,
			"packageAbvId": selection.id
		}
		$.restfulPut('../../api/project/tm/package', jsonData, function(data) {
			reloadNavTree();
		});
	}

	function doPackageMerge() {
		var node = $('#nav').tree('getSelected');
		var packageId = node.id;
		JLEUtil.createModalWin('选择当前目录合并到的目录', `popProjectPackage.html?projectId=${projectId}&callback=packageMergeCallback`);
	}

	function packageMergeCallback(selection) {
		var node = $('#nav').tree('getSelected');
		var jsonData = {
			"packageId" : node.id,
			"packageAbvId": selection.id
		}
		$.restfulPostJson('../../api/project/tm/package/merge', jsonData, function(data) {
			if (data.rows == '-1') {
				$.messager.alert('提示', '目录合并失败', 'info');
			} else {
				reloadNavTree();
			}
		});
	}
</script>
</head>
<body class="easyui-layout">
	<div data-options="region:'north',border:false"
		style="height: 44px; padding: 0px; overflow: hidden">
		<div style='display: none'>
			<input type='hidden' name='csrfmiddlewaretoken'
				value='4v3pUgaR902n7bgrswCbuCLXlo9vAKuk' />
		</div>
		<div id="header">
			<div id="branding" valign="middle">
				<span id="logo" valign="middle"><img
					src="../../static/img/logo.png" alt="SmartAdmin"
					style="width: 206px; height: 38px"></span>
			</div>
			<div id="actions">
				<ul class="actionCont collapsed" id="toggleSidebarUl">
					<li class="actionItem"><a class="aiButton" id="toggleSidebar"
						title="Toggle sidebar" href="#toggle-sidebar"><span>Hide
								sidebar</span></a></li>
				</ul>
				<ul class="actionCont collapsed">
					<li class="actionItem jobboard"><a class="aiButton" id="run"
						title="Run (CTRL + Return)" href="#run"
						onclick="addTab('表模型库概览','TableProjectOverview.html?projectId=' + $.getUrlParam('projectId'))"><span
							class="icon-caret-right"></span>表模型库编辑</a></li>
					<li class="actionItem jobboard"><a class="aiButton" id="run"
						title="Run (CTRL + Return)" href="#run"
						onclick="addTab($(this).text(),'ProjectModelTableInfoList.html?projectId='+ $.getUrlParam('projectId'))"><span
							class="icon-caret-right"></span>在表模型库中查询</a></li>
					<li class="actionItem jobboard"><a class="aiButton" id="run"
						title="Run (CTRL + Return)" href="#run"
						onclick="addTab($(this).text(),'ProjectTmLogList.html?projectId='+ $.getUrlParam('projectId'))"><span
							class="icon-caret-right"></span>表模型库操作日志</a></li>														
				</ul>

			</div>
		</div>
	</div>
	<div data-options="region:'west',title:'导航栏'"
		style="width: 253px; padding: 1px;">
		<ul id="nav" class="easyui-tree"
			data-options="animate:true,
					lines:true,method:'get',
					animate:true,
					url:'../../api/project/tree/package/' + $.getUrlParam('projectId'),
					onContextMenu: onContextMenu,
					onClick: function(node){
						if(node.attributes.package_type == '2'){
							addTab(node.text,'ModelTableInfoList.html?projectId=' + $.getUrlParam('projectId') + '&packageId=' + node.id);
						} else if(node.attributes.package_type == '3'){
							addTab(node.text,'ProjectDictItemInfoList.html?projectId=' + node.id);
						} else if(node.attributes.package_type == '4'){
							addTab(node.text,'ProjectDictOptionInfoList.html?projectId=' + node.id);
						} else if(node.attributes.package_type == '99') {
							addTab(node.text,'DiagramBaseInfoList.html?projectId=' + $.getUrlParam('projectId'));				
						}
					}"
			id="menu_app1">
		</ul>
	</div>

	<div id="mm" class="easyui-menu" style="width:120px;">
		<div onclick="doPackageAdd()">创建下级目录</div>
		<div onclick="doPackageUpdate()">修改当前目录</div>
		<div onclick="doPackageView()">查看当前目录</div>
		<div onclick="doPackageDelete()">删除当前目录</div>
		<div onclick="doPackageMove()">当前目录移动到</div>
		<div onclick="doPackageMerge()">当前目录合并到</div>
	</div>
	
	<div data-options="region:'center',title:''" >
	<div id="tt" class="easyui-tabs" fit="true" border="false">
		<div title="表模型库概览" style="padding:0px" border="false" fit="true">
			<iframe id="centerFrame" name="centerFrame" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>
		</div>
	</div>
</div>
</body>
</html>